#define _CRT_SECURE_NO_WARNINGS 1
bool hasCycle(struct ListNode* head)
{
    if (head == NULL)
        return false;

    if (head->next == NULL)
        return false;

    struct ListNode* slow = head;
    struct ListNode* fast = head;

    while (1)
    {
        fast = fast->next;
        if (fast == slow)
            return true;
        if (fast == NULL)
            return false;
        fast = fast->next;
        if (fast == slow)
            return true;
        if (fast == NULL)
            return false;
        slow = slow->next;
        if (fast == slow)
            return true;
        if (slow == NULL)
            return false;
    }

    return false;
}